//
//  HZ_playView.m
//  HZ_Beautiful_Music
//
//  Created by dllo on 16/4/7.
//  Copyright © 2016年 ui. All rights reserved.
//

#import "HZ_playView.h"
#import "HZ_play_CollectionViewCell.h"
#import "CSL_PlayerPage_ViewController.h"
#import "HZ_play_hs_Model.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
#import "CSLPlayer.h"
#import "HZ_url_hs_Model.h"

@interface HZ_playView ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) UIImageView *image;
@property (nonatomic, strong) UIButton *playbutton;
@property (nonatomic, strong) UICollectionView *coll;
@property (nonatomic, strong) UICollectionViewFlowLayout *flow;
@property (nonatomic, strong) NSMutableArray *array;
@property (nonatomic, strong) CSLPlayer *player;
@property (nonatomic, assign) NSInteger number;
@property (nonatomic, assign) BOOL isPlaye;
@property (nonatomic, assign) NSTimer *MusicTimer;
@property (nonatomic, retain) UISlider *slider;
@property (nonatomic, strong) NSString *string;
@property (nonatomic, strong) NSString *stringplay;
@property (nonatomic, assign) NSInteger numberplay;

@property (nonatomic, strong) NSMutableArray *data;
@property (nonatomic, strong) NSMutableArray *pathArr;
@property (nonatomic, strong) NSFileManager * fileManager;
@property (nonatomic, strong) NSArray * tempFileList;

@property (nonatomic, assign) NSInteger num;
@property (nonatomic, copy) NSString *path;

@property (nonatomic, strong) NSMutableArray *songNameArr;
@property (nonatomic, strong) NSMutableArray *singerNameArr;

@end
@implementation HZ_playView

#define FILEPATH [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];    
}
+(instancetype)playView {
    
    static HZ_playView *playview = nil;
    static dispatch_once_t play;
    
    dispatch_once(&play, ^{
        
        playview = [[HZ_playView alloc] init];
      
    });
    return playview;
}
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.data = [NSMutableArray arrayWithCapacity:0];
        self.playbutton = [UIButton buttonWithType:UIButtonTypeSystem];
        self.playbutton.backgroundColor = [UIColor whiteColor];
        [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-2"] forState:UIControlStateNormal];
        [_playbutton addTarget:self action:@selector(playButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.playbutton];
        self.flow = [[UICollectionViewFlowLayout alloc] init];
        self.flow.minimumInteritemSpacing = 0;
        self.flow.minimumLineSpacing = 0;
        self.flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        self.flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        self.coll = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.flow];
        _coll.backgroundColor = [UIColor whiteColor];
        _coll.delegate = self;
        _coll.dataSource = self;
        _coll.pagingEnabled = YES;
        _coll.bounces = NO;
        [_coll registerClass:[HZ_play_CollectionViewCell class] forCellWithReuseIdentifier:@"HZ_play_CollectionViewCell"];
        [self addSubview:_coll];
        _number = 0;
        [self playbofang];
        self.slider = [[UISlider alloc] initWithFrame:CGRectMake(self.frame.size.width / 7.5, 500, self.frame.size.width / 1.318, self.frame.size.height / 49.06)];
        [self.slider setThumbImage:[UIImage imageNamed:@"iconfont-shutiao-copy"] forState:UIControlStateNormal];
        self.slider.minimumValue = 0.0f;
        self.slider.maximumValue = 1.0f;
        [self addSubview:self.slider];
        self.MusicTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timer) userInfo:nil repeats:YES];
        
        NSNotificationCenter *playnumbea = [NSNotificationCenter defaultCenter];
        [playnumbea addObserver:self selector:@selector(playnumbea:) name:@"7" object:nil];
        
        NSNotificationCenter *hspauseButton = [NSNotificationCenter defaultCenter];
        [hspauseButton addObserver:self selector:@selector(hspauseButton:) name:@"hspauseButton" object:nil];
        
        NSNotificationCenter *hsplayButton = [NSNotificationCenter defaultCenter];
        [hsplayButton addObserver:self selector:@selector(hsplayButton:) name:@"hsplayButton" object:nil];
        
        NSNotificationCenter *hsnextButton = [NSNotificationCenter defaultCenter];
        [hsnextButton addObserver:self selector:@selector(hsnextButton:) name:@"hsnextButton" object:nil];
        
        NSNotificationCenter *hsfrontButton = [NSNotificationCenter defaultCenter];
        [hsfrontButton addObserver:self selector:@selector(hsfrontButton:) name:@"hsfrontButton" object:nil];
        
        NSNotificationCenter *hsitemButton = [NSNotificationCenter defaultCenter];
        [hsitemButton addObserver:self selector:@selector(hsitemButton:) name:@"hsitemButton" object:nil];
        
        NSNotificationCenter *hsdataarray = [NSNotificationCenter defaultCenter];
        [hsdataarray addObserver:self selector:@selector(hsdataarray:) name:@"hsdataarray" object:nil];
        
        NSNotificationCenter *hshotrow = [NSNotificationCenter defaultCenter];
        [hshotrow addObserver:self selector:@selector(hshotrow:) name:@"hshotrow" object:nil];
  
        NSNotificationCenter *hsdataSource = [NSNotificationCenter defaultCenter];
        [hsdataSource addObserver:self selector:@selector(hsdataSource:) name:@"hsdataSource" object:nil];
        
        NSNotificationCenter *hssousuoArray = [NSNotificationCenter defaultCenter];
        [hssousuoArray addObserver:self selector:@selector(hssousuoArray:) name:@"hssousuoArray" object:nil];
      
#pragma mark - 下载界面的通知
        NSNotificationCenter *centerArr = [NSNotificationCenter defaultCenter];
        [centerArr addObserver:self selector:@selector(receiveNotification:) name:@"ARRAY" object:nil];
        
        
        self.path = [NSString stringWithFormat:@"%@/music", FILEPATH];
        self.fileManager = [NSFileManager defaultManager];
        self.tempFileList = [[NSArray alloc] initWithArray:[_fileManager contentsOfDirectoryAtPath:_path error:nil]];

    }
    return self;
}

#pragma mark - 下载
- (void)receiveNotification:(NSNotification *)message {
    self.pathArr = [NSMutableArray arrayWithCapacity:0];
    self.songNameArr = [NSMutableArray arrayWithCapacity:0];
    self.singerNameArr = [NSMutableArray arrayWithCapacity:0];
    self.data = [NSMutableArray arrayWithCapacity:0];
//    点击哪首歌曲
    NSString *numString = message.object[0];
    _number = numString.integerValue;
    
//    路径
    self.data = message.object[1];
    for (int i = 0; i < _data.count; i++) {
        [self.pathArr addObject:[NSString stringWithFormat:@"%@/%@", _path, _data[i]]]
         ;
        NSRange range = [_data[i] rangeOfString:@"-"];
        NSRange range1 = [_data[i] rangeOfString:@"."];
        
        NSString *songString = [_data[i] substringWithRange:NSMakeRange(0, range.location)];
        NSString *nameString = [_data[i] substringWithRange:NSMakeRange(range.location + 1, range1.location - range.location - 1)];
        [self.songNameArr addObject:songString];
        [self.singerNameArr addObject:nameString];

    }
//    NSLog(@"%@", _pathArr); // 歌曲路径
//    NSLog(@"%@", _songNameArr); // 歌曲名
//    NSLog(@"%@", _singerNameArr); // 歌手名
    
//    _coll.contentOffset = CGPointMake((_number)  * (2 * self.bounds.size.width / 3 - 5), 0);
//
//
//    [CSLPlayer shareAVPlayer].name = _songNameArr[_number];
//    NSLog(@"%@", _songNameArr[_number]);
//    [CSLPlayer shareAVPlayer].singerName = _singerNameArr[_number];
//    NSLog(@"%@", _singerNameArr[_number]);
//    [CSLPlayer shareAVPlayer].picUrl = playModel.picUrl;
//    if (playModel.auditionList.count > 0) {
    
//        HZ_url_hs_Model *url = _pathArr[_number];
//        NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
//        int item = str.intValue;
//        if (item >= 600) {
//            [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
//        } else {
//            [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
//        }
//        self.player = [CSLPlayer shareAVPlayer];
//    NSURL *url = [NSURL fileURLWithPath:_pathArr[_number]];
//    NSLog(@"%@", url);
//    self.player = [[CSLPlayer shareAVPlayer] initWithURL:url];
//
//        [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
//        _isPlaye = YES;
//        [CSLPlayer shareAVPlayer].isbutton = YES;
//        [_coll reloadData];
//    }

    
    
}


-(void)hssousuoArray:(NSNotification *)hssousuoArray{
    
    NSArray *array = hssousuoArray.object;
    NSLog(@"%@", array);
    NSString *stry = array[1];
    _number = stry.integerValue ;
    _array = [NSMutableArray arrayWithArray:array[0]];
    //    NSString *stry = array[1];
    _coll.contentOffset = CGPointMake((_number)  * (2 * self.bounds.size.width / 3 - 5), 0);
    HZ_play_hs_Model *playModel = _array[_number];
    //    _number += 1;
    
    NSLog(@"%@", playModel.picUrl);
    [CSLPlayer shareAVPlayer].name = playModel.name;
    [CSLPlayer shareAVPlayer].singerName = playModel.singerName;
    [CSLPlayer shareAVPlayer].picUrl = playModel.picUrl;
    if (playModel.auditionList.count > 0) {
        
        HZ_url_hs_Model *url = playModel.auditionList[1];
        NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
        int item = str.intValue;
        if (item >= 600) {
            [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
        } else {
            [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
        }
        self.player = [CSLPlayer shareAVPlayer];
         [CSLPlayer shareAVPlayer].isbutton = YES;
        [_player playWithUrl:url.url];
        [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
        _isPlaye = YES;

        [self.player play];
        [_coll reloadData];
    }
    
}
-(void)hsdataSource:(NSNotification *)hsdataSource{
 
    NSArray *array = hsdataSource.object;
//    NSLog(@"%@", array);
    NSString *stry = array[1];
    _number = stry.integerValue - 1;
    _array = [NSMutableArray arrayWithArray:array[0]];
    //    NSString *stry = array[1];
    _coll.contentOffset = CGPointMake((_number)  * (2 * self.bounds.size.width / 3 - 5), 0);
    HZ_play_hs_Model *playModel = _array[_number];
    //    _number += 1;
    
    NSLog(@"%@", playModel.picUrl);
    [CSLPlayer shareAVPlayer].name = playModel.name;
    [CSLPlayer shareAVPlayer].singerName = playModel.singerName;
    [CSLPlayer shareAVPlayer].picUrl = playModel.picUrl;
    if (playModel.auditionList.count > 0) {
        
        HZ_url_hs_Model *url = playModel.auditionList[1];
        NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
        int item = str.intValue;
        if (item >= 600) {
            [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
        } else {
            [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
        }
        self.player = [CSLPlayer shareAVPlayer];
        
        [_player playWithUrl:url.url];
        [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
        _isPlaye = YES;
        [CSLPlayer shareAVPlayer].isbutton = YES;
        [_coll reloadData];
    }

}

//电台
-(void)hshotrow:(NSNotification *)hshotrow{
    
    NSArray *array = hshotrow.object;
    _number = 0;
    _array = [NSMutableArray arrayWithArray:array[0]];
//    NSString *stry = array[1];
    _coll.contentOffset = CGPointMake((_number)  * (2 * self.bounds.size.width / 3 - 5), 0);
    HZ_play_hs_Model *playModel = _array[_number];
//    _number += 1;
    [CSLPlayer shareAVPlayer].name = playModel.name;
    [CSLPlayer shareAVPlayer].singerName = playModel.singerName;
    [CSLPlayer shareAVPlayer].picUrl = playModel.picUrl;
    HZ_url_hs_Model *url = playModel.auditionList[1];
    NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
    int item = str.intValue;
    if (item >= 600) {
        [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
    } else {
        [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
    }
    self.player = [CSLPlayer shareAVPlayer];
    [self.player setVolume:1.0];
    [_player playWithUrl:url.url];
    [_coll reloadData];
    
    
    
}

-(void)hsdataarray:(NSNotification *)hsdataarray{
    NSArray *arr = hsdataarray.object;
    _array = [NSMutableArray arrayWithArray:arr[0]];
    NSString *stry = arr[1];
    _number = stry.integerValue - 1;
    _coll.contentOffset = CGPointMake((stry.integerValue - 1) * (2 * self.bounds.size.width / 3 - 5), 0);
    HZ_play_hs_Model *playModel = _array[stry.integerValue - 1 ];
    [CSLPlayer shareAVPlayer].name = playModel.name;
    [CSLPlayer shareAVPlayer].singerName = playModel.singerName;
    [CSLPlayer shareAVPlayer].picUrl = playModel.picUrl;
    HZ_url_hs_Model *url = playModel.auditionList[1];
    NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
    int item = str.intValue;
    if (item >= 600) {
        [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
    } else {
        [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
    }
    self.player = [CSLPlayer shareAVPlayer];
    [_player playWithUrl:url.url];
    [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
    [self.player setVolume:1.0];
    [CSLPlayer shareAVPlayer].isbutton = YES;
    
    _isPlaye = YES;
    [_player play];
    [_coll reloadData];
}
-(void)hsitemButton:(NSNotification *)hsitemButton{
    NSString *ing =[ NSString stringWithFormat:@"%@",hsitemButton.object];
    _coll.contentOffset = CGPointMake(ing.integerValue * (2 * self.bounds.size.width / 3 - 5), 0);
}
-(void)hsfrontButton:(NSNotification *)hsfrontButton{
    NSString *str = hsfrontButton.object;
    _coll.contentOffset = CGPointMake(str.integerValue * (2 * self.bounds.size.width / 3 - 5), 0);
    [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
    _number = str.integerValue;
        self.isPlaye = YES;
}
//下一曲 图片转换
-(void)hsnextButton:(NSNotification *)hsnextButton{
    NSString *str = hsnextButton.object;
    _coll.contentOffset = CGPointMake(str.integerValue * (2 * self.bounds.size.width / 3 - 5), 0);
    [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
    _number = str.integerValue;
    
    self.isPlaye = YES;
}
//按钮换乘播放
-(void)hsplayButton:(NSNotification *)hsplayButton{
    [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
    self.isPlaye = YES;
}
//按钮换成暂停
-(void)hspauseButton:(NSNotification *)hsplayButton{
    [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-2"] forState:UIControlStateNormal];
    self.isPlaye = NO;
}
//大家在听 cell 点击接收
-(void)playnumbea:(NSNotification *)playnumbea{
    NSArray *arr = playnumbea.object;
    _array = [NSMutableArray arrayWithArray:arr[0]];
    NSString *stry = arr[1];
    _coll.contentOffset = CGPointMake((stry.integerValue ) * (2 * self.bounds.size.width / 3 - 5), 0);
    _number = stry.integerValue;
    HZ_play_hs_Model *playModel = _array[stry.integerValue ];
    [CSLPlayer shareAVPlayer].name = playModel.name;
    [CSLPlayer shareAVPlayer].singerName = playModel.singerName;
    [CSLPlayer shareAVPlayer].picUrl = playModel.picUrl;
    HZ_url_hs_Model *url = playModel.auditionList[1];
    NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
    int item = str.intValue;
    if (item >= 600) {
        [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
    } else {
        [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
    }
    self.player = [CSLPlayer shareAVPlayer];
    [self.player setVolume:1.0];
    [_player playWithUrl:url.url];
    [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
    _isPlaye = YES;
    [_player play];
    [_coll reloadData];
    
    
}
- (void)timer{
     self.slider.value = CMTimeGetSeconds(self.player.currentItem.currentTime) / CMTimeGetSeconds(self.player.currentItem.duration);
    if (self.slider.value == 1 && _number <= _array.count - 1) {
        _number += 1 ;
        
        if (_number == _array.count) {
            _number = 0;
            _coll.contentOffset = CGPointMake(_number * (2 * self.bounds.size.width / 3 - 5), 0);
        }
        HZ_play_hs_Model *playModel = _array[_number];
        HZ_url_hs_Model *url = playModel.auditionList[1];
        self.player = [CSLPlayer shareAVPlayer];
        [_player playWithUrl:url.url];
        [self.player setVolume:1.0];
      _coll.contentOffset = CGPointMake(_number * (2 * self.bounds.size.width / 3 - 5), 0);
        [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
        _isPlaye = YES;
        [_player play];
//        if (_number == _array.count - 1) {
//        }
    }
}
//滑动播放

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    _number = (_coll.contentOffset.x )/ (2 * self.bounds.size.width / 3 - 5);
    HZ_play_hs_Model *playModel = _array[_number];
    
    
    if (playModel.auditionList.count > 0) {
        
        HZ_url_hs_Model *url = playModel.auditionList[1];
        NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
        int item = str.intValue;
        if (item >= 600) {
            [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
        } else {
            
            [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
            
        }
        NSNotificationCenter *hsstrnitem = [NSNotificationCenter defaultCenter];
        NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
        
        //        [CSLPlayer shareAVPlayer].name = playModel.name;
        //        [CSLPlayer shareAVPlayer].singerName = playModel.singerName;
        //    [CSLPlayer shareAVPlayer].picUrl = playModel.picUrl;
        [array addObject:[CSLPlayer shareAVPlayer].strn];
        [array addObject:playModel.name];
        [array addObject:playModel.singerName];
        if (playModel.picUrl) {
           [array addObject:playModel.picUrl]; 
        }
        
        [hsstrnitem postNotificationName:@"hsstrnitem" object:array userInfo:nil];
        self.player = [CSLPlayer shareAVPlayer];
        [self.player setVolume:1.0];
        [CSLPlayer shareAVPlayer].isbutton = YES;
        [_player playWithUrl:url.url];
        [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
        _isPlaye = YES;
        [_player play];
        NSLog(@"%ld", (long)_number);
        
        
        
    }
 
    
    
    
    
    
    
}
//-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
//    
//    
//}
-(void)playButton:(UIButton *)button{
    if (self.isPlaye) {
        [self.player pause];
        [self.player setVolume:1.0];
        self.player = [CSLPlayer shareAVPlayer];
        _player.isbutton = NO;
        [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-2"] forState:UIControlStateNormal];
        NSNotificationCenter *hspausebuttonTwo = [NSNotificationCenter defaultCenter];
        [hspausebuttonTwo postNotificationName:@"hspausebuttonTwo" object:nil userInfo:nil];
        self.isPlaye = NO;
    } else{
        [self.player play];
        [self.player setVolume:1.0];
        CSL_PlayerPage_ViewController *csl = [CSL_PlayerPage_ViewController alloc];
        self.player = [CSLPlayer shareAVPlayer];
        _player.isbutton = YES;
        [_playbutton setBackgroundImage:[UIImage imageNamed:@"Unknown-3"] forState:UIControlStateNormal];
        NSNotificationCenter *hsplaybuttonTwo = [NSNotificationCenter defaultCenter];
        [hsplaybuttonTwo postNotificationName:@"hsplaybuttonTwo" object:csl userInfo:nil];
        self.isPlaye = YES;
    }    
}
-(void)layoutSubviews{
    [super layoutSubviews];
    _playbutton.frame = CGRectMake( 2.3 * self.bounds.size.width / 3, self.bounds.size.height / 4,  self.bounds.size.width / 12 , self.bounds.size.height / 2 );
    _coll.frame = CGRectMake(5, 0, 2 * self.bounds.size.width / 3 - 5, self.bounds.size.height);
    self.flow.itemSize = CGSizeMake(2 * self.bounds.size.width / 3 - 5, self.bounds.size.height);
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _array.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HZ_play_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HZ_play_CollectionViewCell" forIndexPath:indexPath];
    cell.model = _array[indexPath.item];
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [_coll deselectItemAtIndexPath:indexPath animated:YES];
    if ([CSLPlayer shareAVPlayer].isbutton == YES) {
        [CSLPlayer shareAVPlayer].isbutton = YES;
    }
    NSNotificationCenter *hsplay = [NSNotificationCenter defaultCenter];
    [hsplay postNotificationName:@"6" object:_array userInfo:nil];
    NSNotificationCenter *hsarray = [NSNotificationCenter defaultCenter];
    
    NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
     HZ_play_hs_Model *playModel = _array[indexPath.row];
    
    
    _stringplay = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
//    [CSLPlayer shareAVPlayer].name = playModel.picUrl;
    [array addObject:_stringplay];
    [array addObject:playModel.name];
    [array addObject:playModel.singerName];
    
    if (playModel.picUrl) {
        [array addObject:playModel.picUrl];
    }
    
    
    [hsarray postNotificationName:@"hsarray" object:array userInfo:nil];
}
#pragma mark - 播放页面数据请求
-(void)playbofang{
    self.array = [NSMutableArray arrayWithCapacity:0];
    [HSAFNetTool GETNetWithUrl:@"http://api.favorite.ttpod.com/favorite/song/plaza?f=384&os=4.4.2&alf=10002266&imei=864783024887313&random=0&from=android&resolution=720x1280&net=2&api_version=1.0&agent=none&v=v8.4.1.2016032512&utdid=VRu%2Blc%2FVSokDANuKLLSuSY%2B5&address=%E8%BE%BD%E5%AE%81%E7%9C%81%E5%A4%A7%E8%BF%9E%E5%B8%82%E6%B2%99%E6%B2%B3%E5%8F%A3%E5%8C%BA%E4%BA%94%E4%B8%80%E8%B7%AF314%E5%8F%B7&longitude=121.544426&user_id=0&latitude=38.883442&language=zh" body:nil headerFile:nil response:HSJSON success:^(id result) {
        
        for (NSDictionary *dic in result[@"data"][@"songs"]) {
            HZ_play_hs_Model *model = [[HZ_play_hs_Model alloc] initWithDataSource:dic];
            [_array addObject:model];
        }
        if (_number == 0) {
            HZ_play_hs_Model *playModel = _array[0];
            [CSLPlayer shareAVPlayer].name = playModel.name;
            [CSLPlayer shareAVPlayer].singerName = playModel.singerName;
            [CSLPlayer shareAVPlayer].name = playModel.picUrl;
            
            NSArray *arr = [NSArray arrayWithArray:playModel.auditionList];
            
            if ( arr.count > 0) {
                HZ_url_hs_Model *url = playModel.auditionList[1];
                NSString *str = [NSString stringWithFormat:@"%0.f", url.duration * 0.001 ];
                int item = str.intValue;
                
                if (item >= 600) {
                    [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"%d:%d", item / 60, item % 60];
                } else {
                    
                    [CSLPlayer shareAVPlayer].strn = [NSString stringWithFormat:@"0%d:%02d", item / 60, item % 60];
                }
                
                
                self.player = [CSLPlayer shareAVPlayer];
                [_player playWithUrl:url.url];

                [self.player setVolume:1.0];
            }
            
           
                    }
        [_coll reloadData];
    } failure:^(NSError *error) {
    }];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
